$('#cgd_tabs').tabs({
    border:false,
    onSelect:function (title) {
        if (title == "入库单打印") {
            // 加载合同文本
            $.ajax({
                type:"POST",
                url:$.webPath() + '/cggl/cgdgl/cgdDetail?cgdId=' + $("#cgddetail_id").val(),
                dataType:"html",
                beforeSend:function () {
                    $.messager.progress();
                },
                success:function (data) {
                    $.messager.progress("close");
                    $('#cgddetail_cgd_id').html(data);
                    if (data.statusCode == 300) {
                    }
                    if (data.statusCode == 200) {
                    }
                }
            });
        }
    }
});

$(function () {
    $("#cgd_tabs .previewImg").lightbox({
        fitToScreen: true,
        loopImages: true,
        imageClickClose: false,
        disableNavbarLinks: true
    });
    $("#cgd_cgdmx_table").datagrid({
        onLoadSuccess:function () {
            $(".datagrid-htable .datagrid-cell").css('text-align', 'center');
        }
    })

    $("#cgd_cgdfy_table").datagrid({
        onLoadSuccess:function () {
            $(".datagrid-htable .datagrid-cell").css('text-align', 'center');
        }
    })


    $('#cgd_newCode').bind('click', function () {
        var newCode = $('#cgd_detail_newCode').val();
        if (newCode == 'on') {
            $("[name='newCode']").hide();
            $('#cgd_detail_newCode').val('off');
            $("[name='colspanCount']").attr('colspan', '5')
        } else if (newCode == 'off') {
            $("[name='newCode']").show();
            $('#cgd_detail_newCode').val('on');
            $("[name='colspanCount']").attr('colspan', '6')
        }
    });

    $('#cgd_oldCode').bind('click', function () {
        var oldCode = $('#cgd_detail_oldCode').val();
        if (oldCode == 'on') {
            $("[name='oldCode']").hide();
            $('#cgd_detail_oldCode').val('off');
            $("[name='colspanCount']").attr('colspan', '5')
        } else if (oldCode == 'off') {
            $("[name='oldCode']").show();
            $('#cgd_detail_oldCode').val('on');
            $("[name='colspanCount']").attr('colspan', '6')
        }
    });

})


//  检查插件
function cgd_detail_checkIsInstall() {
    try {
        var LODOP = getLodop(document.getElementById('CGD_LODOP_OB'), document.getElementById('CGD_LODOP_EM'));
        if ((LODOP != null) && (typeof(LODOP.VERSION) != "undefined"))
            alert("本机已成功安装过Lodop控件!\n  版本号:" + LODOP.VERSION);
    } catch (err) {
        alert("Error:本机未安装或需要升级!");
    }
}


// 打印预览.
function cgd_detail_printPreview() {
    if ($("#cgdzt").val() == "ybc") {
        alert("此单据必须提交后才能进行打印!");
        return;
    }
    var LODOP = getLodop(document.getElementById('CGD_LODOP_OB'), document.getElementById('CGD_LODOP_EM'));
    LODOP.SET_PRINT_STYLEA(0, "NotOnlyHighPrecision", true);
    LODOP.PRINT_INIT("预览送货单");
//    var inputs = document.getElementById("page").getElementsByTagName("input");
//    for (var i = 0; i < inputs.length; i++) {
//        inputs[i].setAttribute("value", inputs[i].value);
//    }
    var strBodyStyle = "<style  type=\"text/css\">" +
        ".textcon{padding:8px;}" +
        ".input-tian{border-top:0 none;border-left:0 none;border-right:0 none;border-bottom: 1px solid black;height:22px;line-height:22px;width:100%;font-weight: bold;}" +
        " select{display:none}" +
        ".tb{width:auto;border-collapse:collapse;border-spacing:0;}" +
        ".tb th{padding:2px 2px 2px 12px;font-size:12px;font-weight:normal;text-align: right;}" +
        ".tb td{padding:2px;font-size:12px;}" +
        ".tb caption{ font-size:24px;height:60px;line-height:20px;}" +
        ".intb{width: 100%;}" +
        ".intb,.intb th,.intb td{border:1px solid black;}" +
        "</style>";
    var strFormHtmltop = strBodyStyle + "<div class='textcon'>" + document.getElementById("cgddetail_print_id").innerHTML + "</div>";
    var strFormHtmlbody = strBodyStyle + "<div class='textcon'>" + document.getElementById("cgddetail_cgd_id").innerHTML + "</div>";
    var strFormHtmlBottom = strBodyStyle + "<div class='textcon'>" + document.getElementById("cgddy_print_end").innerHTML + "</div>";

    var cgd_cgdh = $("#cgd_cgdh").val();
    var cgd_ewmtime = $("#cgd_ewmtime").val();

//    LODOP.SET_PRINT_PAGESIZE(0, '2640', '2790', "CreateCustomPage");
//    LODOP.ADD_PRINT_HTM(50, 80, "82%", "90%", strFormHtmltop + strFormHtmlbody + strFormHtmlBottom);
//    LODOP.ADD_PRINT_BARCODE(50, "85%", 90, 90, 'QRCode', cgd_cgdh + " " + cgd_ewmtime);
//    LODOP.SET_PRINT_PAGESIZE(0, '2640', '1230', "CreateCustomPage");
    LODOP.ADD_PRINT_TABLE(135, "1.5%", "90%", 350, strFormHtmlbody);
    LODOP.SET_PRINT_STYLEA(0, "Vorient", 3);
    LODOP.ADD_PRINT_HTM(20, "1.5%", "90%", 145, strFormHtmltop);
    LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
    LODOP.SET_PRINT_STYLEA(0, "LinkedItem", 1);
    LODOP.ADD_PRINT_HTM(495, "1.5%", "90%", 200, strFormHtmlBottom);
    LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
    LODOP.SET_PRINT_STYLEA(0, "LinkedItem", 1);
//    LODOP.ADD_PRINT_BARCODE(20, "85%", 90, 90, 'QRCode', cgd_cgdh + " " + cgd_ewmtime);
//    LODOP.SET_PRINT_STYLEA(0, "QRCodeVersion", 3);
    LODOP.ADD_PRINT_TEXT(5, "80%", 135, 20, "总页号：第#页/共&页");
    LODOP.SET_PRINT_STYLEA(0, "ItemType", 2);
    LODOP.SET_PRINT_STYLEA(0, "Horient", 1);
    LODOP.PREVIEW();
}

// 打印
function cgd_detail_print() {
    var LODOP = getLodop(document.getElementById('CGD_LODOP_OB'), document.getElementById('CGD_LODOP_EM'));
    LODOP.SET_PRINT_STYLEA(0, "NotOnlyHighPrecision", true);
    LODOP.PRINT_INIT("打印送货单");
    LODOP.SET_PRINT_STYLE("FontSize", 18);

//    var inputs = document.getElementById("page").getElementsByTagName("input");
//    for (var i = 0; i < inputs.length; i++) {
//        inputs[i].setAttribute("value", inputs[i].value);
//    }
    var strBodyStyle = "<style  type=\"text/css\">" +
        ".textcon{padding:8px;}" +
        ".input-tian{border-top:0 none;border-left:0 none;border-right:0 none;border-bottom: 1px solid black;height:22px;line-height:22px;width:100%;font-weight: bold;}" +
        " select{display:none}" +
        ".tb{width:auto;border-collapse:collapse;border-spacing:0;}" +
        ".tb th{padding:2px 2px 2px 12px;font-size:12px;font-weight:normal;text-align: right;}" +
        ".tb td{padding:2px;font-size:12px;}" +
        ".tb caption{ font-size:24px;height:60px;line-height:20px;}" +
        ".intb{width: 100%;}" +
        ".intb,.intb th,.intb td{border:1px solid black;}" +
        "</style>";
    var strFormHtmltop = strBodyStyle + "<div class='textcon'>" + document.getElementById("cgddetail_print_id").innerHTML + "</div>";
    var strFormHtmlbody = strBodyStyle + "<div class='textcon'>" + document.getElementById("cgddetail_cgd_id").innerHTML + "</div>";
    var strFormHtmlBottom = strBodyStyle + "<div class='textcon'>" + document.getElementById("cgddy_print_end").innerHTML + "</div>";

    var cgd_cgdh = $("#cgd_cgdh").val();
    var cgd_ewmtime = $("#cgd_ewmtime").val();

//    LODOP.SET_PRINT_PAGESIZE(0, '2640', '2790', "CreateCustomPage");
//    LODOP.ADD_PRINT_HTM(50, 80, "82%", "90%", strFormHtmltop + strFormHtmlbody + strFormHtmlBottom);
//    LODOP.ADD_PRINT_BARCODE(50, "85%", 90, 90, 'QRCode', cgd_cgdh + " " + cgd_ewmtime);

    LODOP.ADD_PRINT_TABLE(135, "1.5%", "90%", 350, strFormHtmlbody);
    LODOP.SET_PRINT_STYLEA(0, "Vorient", 3);
    LODOP.ADD_PRINT_HTM(20, "1.5%", "90%", 145, strFormHtmltop);
    LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
    LODOP.SET_PRINT_STYLEA(0, "LinkedItem", 1);
    LODOP.ADD_PRINT_HTM(495, "1.5%", "90%", 200, strFormHtmlBottom);
    LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
    LODOP.SET_PRINT_STYLEA(0, "LinkedItem", 1);
//    LODOP.ADD_PRINT_BARCODE(20, "85%", 90, 90, 'QRCode', cgd_cgdh + " " + cgd_ewmtime);
//    LODOP.SET_PRINT_STYLEA(0, "QRCodeVersion", 3);
    LODOP.ADD_PRINT_TEXT(5, "80%", 135, 20, "总页号：第#页/共&页");
    LODOP.SET_PRINT_STYLEA(0, "ItemType", 2);
    LODOP.SET_PRINT_STYLEA(0, "Horient", 1);
    LODOP.PREVIEW();
}

function viewCghtDetail(id) {
    $.window({
        title:'详细信息',
        iconCls:'icon-tip',
        url:$.webPath() + "/htgl/cghtgl/cghtgl_detail?cghtId=" + id,
        width:1050,
        height:500,
        modal:true,
        isMax:false
    })
}

function viewXsdDetail(id) {
    $.window({
        title:'详细信息',
        iconCls:'icon-tip',
        url:$.webPath() + "/xsgl/xsdgl/xsdgl_detail?xsdId=" + id,
        width:1050,
        height:500,
        modal:true,
        isMax:false
    })
}

function viewXshtDetail(id) {
    $.window({
        title:'详细信息',
        iconCls:'icon-tip',
        url:$.webPath() + "/htgl/xshtgl/xshtgl_detail?xshtId=" + id,
        width:1050,
        height:500,
        modal:true,
        isMax:false
    })
}
